export const state = () => {
  return {
    themes: ['dark', 'white'],
    theme: 'dark',
    counter: 0,
    ua: '',
    os: false,
    isMobile: false,
    isWechat: false,
  }
}
export const mutations = {
  TOGGLE_THEME(state, theme) {
    state.theme = theme
  },
  INCREMENT(state) {
    state.counter++
  },
  INIT_REQ(state, ua) {
    state.ua = ua
    if (state.ua.includes('iPhone') || state.ua.includes('iPad')) {
      state.os = 'IOS'
      state.isMobile = true
    } else if (state.ua.includes('Android')) {
      state.os = 'Android'
      state.isMobile = true
    } else if (state.ua.includes('Linux')) {
      state.os = 'Linux'
    } else if (state.ua.includes('Macintosh')) {
      state.os = 'MacOS'
    } else {
      state.os = 'Windows'
    }
    if (state.ua.includes('micromessenger')) {
      state.isWechat = true
    }
    this.$log(state)
  },
}
export const actions = {
  nuxtServerInit({ commit }, { req }) {
    if (process.server) {
      // commit('INIT_REQ', req.headers['user-agent'])
      this.$log('server side render undefined req')
    } else {
      commit('INIT_REQ', navigator.userAgent)
    }
    this.$log('serve init')
  },
}
